﻿using System;
using System.Web.UI;
using OpenWaves;
using OpenWaves.ActivityFeed;
using OpenWaves.ActivityFeed.Web;
using OpenWaves.ActivityFeed.Web.Controls;

namespace ActivityFeed.SharePoint.Sample.ActivityFeedWebPart
{
    public partial class ActivityFeedWebPartUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            ServiceLocator.SetResolver(new BasicResolver().Register<IDocumentSessionProvider>(new DocumentSessionPerRequestProvider()));

            //OpenWaves.Web.AssemblyResourceVirtualPathProvider.EnsureRegistered();

            var activityFeedBase = new ActivityFeedBase();

            //this.session = this.CreateDocumentSession();
            IActivityFeedService activityFeedService = new ActivityFeedService(DocumentSessionPerRequestProvider.CurrentDocumentSession);

            activityFeedBase.ActivityFeedOptionsDtoBuilder = new ActivityFeedOptionsDtoBuilder
            (
                    ServiceLocator.Resolve<IUserIdentityProvider>(),
                    activityFeedService,
                    new SharePointDummyUserProfileProvider(),
                    ServiceLocator.Resolve<IUserGroupMembershipProvider>()
            );


            this.Controls.Remove(this.template);
            activityFeedBase.Template = this.template;

            this.Controls.Remove(this.updateTemplate);
            activityFeedBase.UpdateTemplate = this.updateTemplate;

            this.Controls.Remove(this.postTemplate);
            activityFeedBase.UpdateContentTemplates.Add(this.postTemplate);

            this.Controls.Remove(this.commentTemplate);
            activityFeedBase.CommentTemplate = this.commentTemplate;

            plhMain.Controls.Add(activityFeedBase);
        }
    }
}
